function checkValidGrid(grid: number[][]): boolean {
    // 以左上为圆点，横为x，纵为y  arr[y][x]
    let x:number = 0,y:number = 0
    let count = 0
    const n = grid.length -1
    const arr: number[][] = [[1,2],[1,-2],[2,1],[2,-1],[-1,2],[-1,-2],[-2,1],[-2,-1]]
    if (grid[y][x]) {
        return false
    } else {
        for (;count<grid.length * grid.length - 1;){
            let b = false
            for (let i=0;i<arr.length;i++) {
                if (y+arr[i][0]>= 0&& y+arr[i][0]<=n && x+arr[i][1]>=0 && x+arr[i][1]<=n && grid[y+arr[i][0]][x+arr[i][1]] === grid[y][x] + 1) {
                    count+=1
                    x += arr[i][1]
                    y += arr[i][0]
                    b = true
                    break
                }
            }
            console.log('stage',x,y,grid[y][x])
            if (!b) count = grid.length * grid.length
        }
        if (count===grid.length * grid.length-1) {
            return true
        } else {
            return false
        }
    }
};

// const grid = [[0,11,16,5,20],[17,4,19,10,15],[12,1,8,21,6],[3,18,23,14,9],[24,13,2,7,22]]
// const grid = [[0,3,6],[5,8,1],[2,7,4]]
const grid = [[0,13,1,7,20],[3,8,19,12,15],[18,2,14,21,6],[9,4,23,16,11],[24,17,10,5,22]]

console.log(checkValidGrid(grid))